//
//  AY_BookVpCell2.m
//  AiYue
//
//  Created by boWen on 2023/10/30.
//

#import "AY_BookVpCell2.h"

@interface AY_BookVpCell2 ()
@property (nonatomic,strong) UIView * bg_View;//底部圆角
@property (nonatomic,strong) UILabel * wenxinLabel;
@property (nonatomic,strong) UILabel * wenContentLabel;
@property (nonatomic,strong) UIImageView *adImg;
@property (nonatomic,strong) ConfigModel *configModel;
@property (nonatomic,strong) BannerModel *bannerModel;
@end

@implementation AY_BookVpCell2


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}


- (void)addAllSubviewsWithUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = COLOR_Bg;
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(6) andAddSubView:self.contentView];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
    
    self.adImg = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:[UIColor redColor] andRadius:YNUM(8) andAddSubView:self.bg_View];
    [self.adImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bg_View).offset(YNUM(12));
        make.right.equalTo(self.bg_View).offset(-YNUM(12));
        make.top.equalTo(self.bg_View);
        make.height.mas_equalTo(YNUM(70));
    }];

    self.wenxinLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"温馨提示" andTextColor:COLOR(@"#909090") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.wenxinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.adImg.mas_bottom).offset(YNUM(12));
        make.left.equalTo(self.bg_View).offset(YNUM(12));
    }];
    
    self.wenContentLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#909090") andBgColor:nil andFont:YFont(12) andLines:0 andRadius:0 andAddSubView:self.bg_View];
    self.wenContentLabel.userInteractionEnabled = YES;
    [self.wenContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.wenxinLabel.mas_bottom).offset(YNUM(8));
        make.left.equalTo(self.bg_View).offset(YNUM(12));
        make.right.equalTo(self.bg_View).offset(YNUM(-12));
        make.bottom.equalTo(self.bg_View).offset(YNUM(-12));
    }];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(kefuAction)];
    [self.wenContentLabel addGestureRecognizer:tap];
}

- (void)kefuAction {
    AY_WebViewController *webVC = [[AY_WebViewController alloc] init];
    webVC.fullPath = [NSString stringWithFormat:@"%@%@",self.configModel.web_url,self.configModel.kfAdress];
    [[AYTool viewControllerWith:self].navigationController pushViewController:webVC animated:YES];
}

- (void)sendConfigModel:(ConfigModel *)configModel andBannerModel:(BannerModel *)bannerModel {
    _configModel = configModel;
    _bannerModel = bannerModel;
    [self.adImg sd_setImageWithURL:[NSURL URLWithString:bannerModel.image] placeholderImage:YImage(@"placeholderImage")];
    if (kStringIsEmpty(bannerModel.image)) {
        [self.adImg mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0.001);
        }];
    }
    configModel.vip_intro = [configModel.vip_intro stringByReplacingOccurrencesOfString:@"#" withString:@"\n"];
    self.wenContentLabel.text = configModel.vip_intro;
    if (kStringIsEmpty(self.wenContentLabel.text) == NO) {
        NSString *labelText = self.wenContentLabel.text;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
        NSMutableParagraphStyle *styles = [NSMutableParagraphStyle new];
        styles.lineSpacing  = 8;
        NSRange rangeA = [self.wenContentLabel.text rangeOfString:@"联系客服"];
        [attributedString addAttribute:NSForegroundColorAttributeName value:COLOR(@"#9C5839") range:rangeA];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:styles range:NSMakeRange(0, [labelText length])];
        self.wenContentLabel.attributedText = attributedString;
    }
}
@end
